home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_06
/
1106044a
< prev
next >
Wrap
Text File
|
1993-04-17
|
2KB
|
104 lines
/* funlib.c */
#include <stdlib.h>
#include <math.h>
#include "funlib.h"
void fun_unit_step(
const long int wave_ary_len,
double *waveform)
{
auto unsigned long int wave_index;
for ( wave_index = 1;
wave_index <= wave_ary_len;
wave_index++)
{
waveform[wave_index]
= 1.0 / (double)wave_ary_len;
}
return;
}
void fun_noise(const long int wave_ary_len,
const double noise_width,
double *waveform)
{
auto unsigned long int wave_index;
for (wave_index = 0;
wave_index < wave_ary_len;
wave_index++)
{
waveform[wave_index]
+= noise_width
* ((double)rand() / (double)RAND_MAX);
}
return;
}
void fun_step_real(const long int wave_ary_len,
double *waveform)
{
auto unsigned long int i,
temp_len
= wave_ary_len / 2;
fun_gaussian_density(temp_len, waveform);
for (i = 0; i < wave_ary_len; i++)
{
waveform[i] = 1.0 - waveform[i];
}
for (i = 1; i < temp_len; i++)
{
waveform[i]
= waveform[i + 1 + (temp_len / 2)];
}
for (i = temp_len / 2; i < wave_ary_len; i++)
{
waveform[i] = .999;
}
waveform[0] = 0.0;
return;
}
void fun_gaussian_density(const long int wave_ary_len,
double *waveform)
{
auto unsigned long int i;
auto double x,
mean,
std_dev;
for (i = 0; i < wave_ary_len; i++)
{
mean = (double)wave_ary_len / 2.0;
std_dev = (0.7 * wave_ary_len) / 6.0;
x = (double)i;
waveform[i]
= exp(- pow((x - mean), 2.0)
/ (2.0 * pow(std_dev, 2.0)));
}
waveform[0] = 0.0;
return;
}
void fun_unit_gauss_dens(const long int wave_ary_len, double *waveform)
{
auto double area = 0.0;
auto unsigned long int wave_index;
fun_gaussian_density(wave_ary_len, waveform);
for (wave_index = 0;
wave_index < wave_ary_len; wave_index++)
{
area += waveform[wave_index];
}
for (wave_index = 0; wave_index < wave_ary_len;
wave_index++)
{
waveform[wave_index] /= area;
}
return;
}